package com.example.demospringboot.controller.employcontroller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.MediaTypes;
import org.springframework.hateoas.mvc.ControllerLinkBuilder;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import com.example.demospringboot.domains.Department;
import com.example.demospringboot.domains.Employee;
import com.example.demospringboot.mapper.DepartmentMapper;
import com.example.demospringboot.mapper.EmployeeMapper;
import com.example.demospringboot.service.*;

@RestController
@RequestMapping("/employee")
public class EmployeeController {
	private static Logger logger = LoggerFactory.getLogger(EmployeeController.class);

	@Autowired
	EmpoyeeService empService;

	@RequestMapping(value="/createEmp", method = RequestMethod.POST)
	public Employee createEmployee(@RequestBody Employee emp){

		return empService.createEmployee(emp);
	}

	@RequestMapping(value="/getEmp/{empId}",method = RequestMethod.GET)
	public Employee getEmplyee(@PathVariable Long empId){
		logger.info("calling employee service");
		return empService.getEmplyee(empId);
	}

	@RequestMapping(value="/getEmps",method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	public List<Employee> getEmployees(){
		List<Employee> employees = empService.getEmployees();
		return employees;
	}


	@RequestMapping(value="/updateEmp",method = RequestMethod.POST)
	public Employee updateEmployee(@RequestBody Employee emp){
		return empService.updateEmployee(emp);
	}

	@RequestMapping(value="/delEmp/{empId}", method = RequestMethod.PUT )
	public boolean deleteEmployee(@PathVariable Long empId){

		return empService.deleteEmployee(empId);
	}
}
